package remato.domain.common.impl;

import java.util.HashSet;
import java.util.Set;

import remato.common.domain.helpers.Nameable;
import remato.common.domain.impl.base.DomainName;
import remato.common.domain.impl.internal.ProjectChild;
import remato.domain.common.Project;
import remato.domain.common.PropertySet;
import remato.domain.common.RequirementSystem;
import remato.domain.common.Stakeholder;

public class RequirementSystemImpl extends DomainName implements RequirementSystem, Nameable {

	private Set<Project> rootProjects;
	private Set<Stakeholder> stakeholders;
	private Set<PropertySet> propertySets; 
	private boolean hasChildren;

	public RequirementSystemImpl() {
		super();
		rootProjects = new HashSet<Project>();
		stakeholders = new HashSet<Stakeholder>();
		propertySets = new HashSet<PropertySet>();
		hasChildren = false;
	}


	public Set<PropertySet> getPropertySets() {
		return propertySets;
	}


	public void setPropertySets(Set<PropertySet> propertySets) {
		this.propertySets = propertySets;
		hasChildren = false;
	}


	public Set<Project> getProjectChildren() {
		return rootProjects;
	}


	public void setProjectChildren(Set<Project> rootProjects) {
		this.rootProjects = rootProjects;
		hasChildren = false;
	}


	public Set<Stakeholder> getStakeholders() {
		return stakeholders;
	}


	public void setStakeholders(Set<Stakeholder> stakeholders) {
		this.stakeholders = stakeholders;
		hasChildren = false;
	}

	public boolean addStakeholder(Stakeholder stakeholder) {
		return stakeholders.add(stakeholder);
	}
	public boolean removeStakeholder(Stakeholder stakeholder) {
		return stakeholders.remove(stakeholder);
	}

	public boolean addPropertySet(PropertySet propertySet) {
		return propertySets.add(propertySet);
	}
	public boolean removePropertySet(PropertySet propertySet) {
		return propertySets.remove(propertySet);
	}
	
    public boolean removeProjectChild(Project child) {
		return rootProjects.remove(child);
	}

    public boolean addProjectChild(Project child) {
		if (null != child.getProjectParent()) {
			child.getProjectParent().removeProjectChild(child);
			((ProjectChild)child).setProjectParent(null);
		}
		return rootProjects.add(child);
    }

	public boolean hasChildren() {
		return hasChildren || ! rootProjects.isEmpty() || ! stakeholders.isEmpty() || ! propertySets.isEmpty();
	}
	public void setHasChildren(boolean hasChildren) {
		this.hasChildren = hasChildren;
	}
	
	
}
